#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
struct p{
    int a, b;
}c[MAXN];
bool cmp(p x, p y){
    return x.b < y.b;
}
int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c[i].a >> c[i].b;
    }
    sort(c + 1, c + n + 1, cmp);
    int end = c[1].b;
    int ans = 1;
    for (int i = 2; i <= n; i++){
        if (c[i].a >= end){
            ans++;
            end = c[i].b;
        }
    }
    cout << ans;
    return 0;
}